"""
订单管理视图
"""
from rest_framework import serializers
from rest_framework.generics import ListAPIView, UpdateAPIView
from rest_framework.viewsets import ModelViewSet
from orders.models import OrderInfo
from meiduo_admin.serializers.order_serializers import *
from meiduo_admin.paginations import MyPage
class OrderListView(ListAPIView, UpdateAPIView):
    queryset = OrderInfo.objects.all()
    serializer_class = OrderSimpleSerializer
    pagination_class = MyPage

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return self.queryset.filter(order_id__contains=keyword)
        return self.queryset.all()

class OrderView(ModelViewSet):
    queryset = OrderInfo.objects.all()
    serializer_class = OrderSerializer
